using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace RecoFace
{
    using AForge.Video.DirectShow;

    public partial class FrmDevice : Form
    {
        FilterInfoCollection videoDevices;
        private string device;

        public string VideoDevice
        {
            get { return device; }
        }

        public FrmDevice()
        {
            InitializeComponent();

            // Show device list
            try
            {
                // Enumerate video devices
                videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

                if (videoDevices.Count == 0)
                    throw new ApplicationException();

                // Add all devices to combobox
                foreach (FilterInfo device in videoDevices)
                {
                    cbbDevice.Items.Add(device.Name);
                }
            }
            catch (ApplicationException)
            {
                cbbDevice.Items.Add("No local capture devices");
                cbbDevice.Enabled = false;
                btnOk.Enabled = false;
            }

            cbbDevice.SelectedIndex = 0;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            device = videoDevices[cbbDevice.SelectedIndex].MonikerString;
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}